<?php

namespace app\common\model;

use think\Model;

/**
 * 活动模型
 */
class ActivityModel extends Model
{

    protected $name = 'activity';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';


    public function getStatusTextAttr($value, $data)
    {
        if (empty($data['begin_time'])) return '';
        $begin_time = strtotime($data['begin_time']);
        //结束时间 活动当天的24点
        $end_time = strtotime(date('Y-m-d 23:59:59', $begin_time));
        $time = time();
        if ($time <= $begin_time) {
            $status = __('报名中');
            if (!empty($data['login_user_id'])) {
                $count = ActivitySignModel::where('activity_id', $data['id'])
                    ->where('user_id', $data['login_user_id'])
                    ->count();
                if ($count) {
                    $status = __('已报名');
                }
            }

        } elseif ($time < $end_time) {
            $status = __('活动中');
        } else {
            $status = __('已截止');
        }
        return $status;
    }

    public function getThumbAttr($value, $data)
    {
        return cdnurl($value,true);
    }

    public function getRouteThumbAttr($value, $data)
    {
        return cdnurl($value,true);
    }

}
